package com.itheima.pinda.controller.base;


import com.itheima.pinda.DTO.entity.dto.PdGoodsTypeDTO;
import com.itheima.pinda.DTO.entity.pojo.base.PdGoodsType;
import com.itheima.pinda.DTO.entity.vo.Results;
import com.itheima.pinda.DTO.entity.vo.StatusCode;
import com.itheima.pinda.feign.service.common.PdGoodsTypeService;
import com.itheima.pinda.feign.service.truck.PdTruckTypeGoodsTypeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 货物类型表 前端控制器
 * </p>
 *
 * @author xy
 * @since 2021-11-08
 */
@RestController
@RequestMapping("/base/goodsType")
public class PdGoodsTypeController {

    @Autowired
    private PdGoodsTypeService pdGoodsTypeService;

    @Autowired
    private PdTruckTypeGoodsTypeService pdTruckTypeGoodsTypeService;

    /**
     * 添加货物类型
     * @param goodsTypeDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "添加货物类型")
    public Results saveGoodsType(@RequestBody PdGoodsTypeDTO goodsTypeDTO){
        PdGoodsType pdGoodsType = new PdGoodsType();
        BeanUtils.copyProperties(goodsTypeDTO,pdGoodsType);
        boolean save = pdGoodsTypeService.save(pdGoodsType);
        if (save){
            return new Results(true, StatusCode.OK,"添加成功",null);
        }
       return new Results(false,StatusCode.ERROR,"添加失败",null);
    }

    /**
     * 根据id查询货物类型
     * @param id 货物类型 id
     * @return  货物类型信息
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据货物类型id查询货物编号")
    public Results findById(@PathVariable(value = "id") String id){
        PdGoodsType goodsType = pdGoodsTypeService.findById(id);
        return new Results(true,StatusCode.OK,"查询成功",goodsType);
    }
    /**
     * 查询所有
     * @return
     */
    @PostMapping("")
    @ApiOperation("查询所有")
    public List<PdGoodsType> findAll(){
        return  pdGoodsTypeService.findAll();
    }

}












































